package com.cx.mall.seckill.service.impl;


import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.cx.mall.common.entity.seckill.entity.SeckillGoods;
import com.cx.mall.seckill.mapper.SeckillGoodsMapper;
import com.cx.mall.seckill.service.ISeckillGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zs
 * @since 2025-08-07
 */
@Service
@CacheConfig(cacheNames = "seckill-goods")   // 缓存名称
public class SeckillGoodsServiceImpl extends ServiceImpl<SeckillGoodsMapper, SeckillGoods> implements ISeckillGoodsService {
    @Cacheable( key = "'listByActivityById_'+#activityId")  // 缓存key,如果有key,在缓存中去查数据，如果没有key,在数据库中查数据
    @Override
    public List<SeckillGoods> listByActivityById(Integer activityId) {
        QueryChainWrapper<SeckillGoods> queryChainWrapper = new QueryChainWrapper<>(baseMapper);
        List<SeckillGoods> list = queryChainWrapper.eq("activity_id", activityId).list();
        if(list.isEmpty()){
            return null;
        }
        return list;
    }
}
